package impl;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * Created by bgt on 2017/10/4.
 */
public class Test {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Iterator<HelloService> its = ServiceLoader.load(HelloService.class).iterator();
        if (its.hasNext()) {
            HelloService hello = its.next();
            Method method = hello.getClass().getDeclaredMethod("msg");
            method.setAccessible(true);
            method.invoke(hello, null);
        } else {
            System.out.println("no>...");
        }
    }
}
